package main.java.indi.zyj.classic150;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Combine {

    List<List<Integer>> res = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();

    List<List<Integer>> combine(int n, int k){
        backtrack(1, n, k);
        return res;
    }

    private void backtrack(int start, int n, int k) {
        if (path.size() == k) {
            res.add(new LinkedList<>(path));
            return;
        }

        for (int i = start; i <= n - (k - path.size()) + 1; i++) {
            path.addLast(i);
            backtrack(i + 1, n, k);
            path.removeLast();
        }
    }


}
